/*
 * @Author: wangqizhang
 * @Date: 2024-05-24 15:43:21
 * @LastEditors: wangqizhang
 * @LastEditTime: 2024-05-24 18:54:33
 * @FilePath: /suixinji-react/src/components/SuperRich/index.tsx
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
import { AiEditor } from 'aieditor';
import 'aieditor/dist/style.css';
import { useEffect, useRef } from 'react';

const SuperRich = (props: any) => {
  const { value, onChange } = props;
  const ref = useRef<any>(null);
  useEffect(() => {
    if (ref.current) {
      const aiEditor = new AiEditor({
        element: ref.current,
        placeholder: '点击输入内容...',
        content: value,
        onChange: (content) => {
          onChange(content.getHtml());
        },
        ai: {
          models: {
            spark: {
              appId: '***',
              apiKey: '***',
              apiSecret: '***',
            },
          },
        },
      });
      return () => {
        aiEditor.destroy();
      };
    }
  }, []);
  return <div ref={ref} style={{ height: '500px', minHeight: '500px' }}></div>;
};
export default SuperRich;
